from django.db import models

# Create your models here.


class Cate(models.Model):
    """
    商品分类
    """
    name = models.CharField(max_length=30)
    cid = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True)

    class Meta:
        db_table = 'cate'

    def __str__(self):
        return self.name


class Group(models.Model):
    """
    分类分组
    """
    name = models.CharField(max_length=30)
    cate = models.OneToOneField(Cate, on_delete=models.CASCADE)

    class Meta:
        db_table = 'cate_group'

    def __str__(self):
        return self.name


class Brand(models.Model):
    cate = models.ManyToManyField(to=Cate)
    name = models.CharField(max_length=10,verbose_name='品牌名')
    logo = models.CharField(max_length=200,verbose_name='品牌logo')
    class Meta:
        db_table = 'brand'
    def __str__(self):
        return self.name


class Color(models.Model):
    """
    颜色
    """
    name = models.CharField(max_length=20)

    class Meta:
        db_table = 'color'

    def __str__(self):
        return self.name


class Version(models.Model):
    """
    版本
    """
    name = models.CharField(max_length=30)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'version'


class Goods(models.Model):
    """
    商品表
        名称、描述、价格、颜色、版本、库存、商品详情、商品默认图片、分类
    """
    name = models.CharField(max_length=100)
    describe = models.CharField(max_length=500)
    price = models.DecimalField(max_digits=8, decimal_places=2)
    stock = models.IntegerField(default=0)
    detail = models.TextField()
    image_default = models.ImageField(upload_to='goods')
    color = models.ManyToManyField(Color)
    version = models.ManyToManyField(Version)
    cate = models.ForeignKey(Cate, on_delete=models.CASCADE)
    # 默认都在卖
    isselling = models.BooleanField(default=True)

    class Meta:
        db_table = 'goods'

    def __str__(self):
        return self.name